#include "hpy.h"
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char* argv[])
{
    registerGen(argc, argv, 1);
    auto [len, k, h, w] = tuple{opt<int>(1), opt<int>(2), opt<int>(3), opt<int>(4)};
    int n = rnd.wnext(len / 2, len, 3), m = rnd.wnext(len / 2, len, 3);
    if(h == 0) h = n * m;
    println(n, m, k);
    for(int i = 0; i < n; i ++) {
        vector<int> a(m);
        for(auto &x : a) x = rnd.wnext(1, h, w);
        println(a);
    }
    for(int i = 0; i < k; i ++) {
        println(rnd.next(n) + 1, rnd.next(m) + 1);
    }
}
